package com.testnacos.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ChacheImpl {

    //模拟熔断缓存

    @CacheResult(cacheKeyMethod = "myChache")
    @HystrixCommand(fallbackMethod = "killyouHystrixFal",//方法也
            commandKey = "killyouHystrixseeChache")
    public String killyouHystrixseeChache()  {
        System.out.println("走方法killyouHystrixseeChache");
        return "";
    }

    public String myChache()  {
        System.out.println("这也是666myChache");
        return "myChache";
    }
    public String killyouHystrixFal(){
        System.out.println("这也是666");
        return "这也是666";
    }

    @HystrixCollapser(batchMethod = "killyouHystrixtryCollapsers"
    ,scope = com.netflix.hystrix.HystrixCollapser.Scope.GLOBAL,
            collapserProperties = {
            @HystrixProperty(name="timerDelayInMilliseconds",value="1000")
            }
    )
    public String killyouHystrixtryCollapser(String ags){
  System.out.println(ags);
        return ags+"必死";
    }

    @HystrixCommand
    public List<String> killyouHystrixtryCollapsers(List<String> ags){//记住返回的一定是LIST
        System.out.println(ags);

        return ags;
    }
}
